#!/usr/bin/python

""" CLASS/MODULE:
    Purpose:
"""
__author__ = 'liwei79@gmail.com'

from CGAux import *

class CodeGenerator(CGAux):
    def __init__(self, lexer, parser, srcText):
        CGAux.__init__(self, self)
        self.lexer = lexer
        self.parser = parser
        self.srcText = srcText
        self.aux = CGAux(self)
        self.symTable = SymbolTable()

    def doParseCg(self):
        assert(self.lexer)
        self.initProgram()
        self.parser.parse(self.srcText, lexer = self.lexer)

    def __repr__(self):
        str = "Create CodeGenerator"
        return str + "\n"

class SymbolTable():
    def __init__(self):
        self.symTable = {}
        self.symStack = []

    def addSymbol(self, opndsym, type):
        self.symTable[opndsym.getSym()] = [opndsym, type]

    def lookupSymbol(self, name):
        return self.symTable[name]

    def pushSym(self, opndsym):
        self.symStack.append(opndsym)

    def popAndDeclSyms(self, type):
        for sym in self.symStack:
            self.symTable[sym.getSym()] = [sym, type]
        self.symStack = []
        return


